package com.wuye.services.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wuye.common.services.impl.BaseManagerImpl;
import com.wuye.common.vo.RetVO;
import com.wuye.constants.BaseConstants;
import com.wuye.dao.UserDao;
import com.wuye.entity.User;
import com.wuye.services.LoginServiceManager;

@Service("loginServiceManager")
public class LoginServiceManagerImpl extends BaseManagerImpl implements LoginServiceManager {
	
	@Autowired
	private UserDao userDao;
	

	public User login(String username, String password) throws Exception {
		User user=userDao.getUserByAccountAndPwd(username, password);
		if(user!=null){
			return user;
		}
		return null;
	}
	public RetVO login2(String username, String password) throws Exception {
		RetVO retVo = RetVO.newInstance(BaseConstants.RET_TRUE, "");
		User user=userDao.getUserByAccountAndPwd(username, password);
		if(user!=null){
			Map<String,Object> retMap = new HashMap<String,Object>();
			retMap.put("user", user);
			if (user.getOwnerCompany() != null){
				retMap.put("companyId", user.getOwnerCompany().getId());
				retMap.put("companyName", user.getOwnerCompany().getCompanyName());
			}
			if (user.getOwnerCommunity() != null){
				retMap.put("communityId", user.getOwnerCommunity().getId());

				retMap.put("communityName", user.getOwnerCommunity().getCommunityName());
				
			}
			if (user.getOwnerOrg() != null){
				retMap.put("orgId", user.getOwnerOrg().getId());
			}
			retVo.setObject(retMap);
			return retVo;
		}else{
			retVo.setResult(BaseConstants.RET_FALSE);
		}
		return retVo;
	}
	public List queryMenuPrivileges(Map<String, Object> map) {
		// TODO Auto-generated method stub
//		return loginDao.queryMenuPrivileges(map);
		return null;
	}

}
